package com.wilmer.carousel.controller;

import com.wilmer.common.annotation.Anonymous;
import com.wilmer.common.annotation.Log;
import com.wilmer.common.core.controller.BaseController;
import com.wilmer.common.core.domain.AjaxResult;
import com.wilmer.common.core.page.TableDataInfo;
import com.wilmer.common.enums.BusinessType;
import com.wilmer.common.utils.poi.ExcelUtil;
import com.wilmer.carousel.domain.WechatCarousel;
import com.wilmer.carousel.domain.vo.ShowVo;
import com.wilmer.carousel.service.IWechatCarouselService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 轮播图Controller
 * 
 * @author hans
 * @date 2024-03-15
 */
@Api(tags = "小程序轮播图管理接口")
@RestController
@RequestMapping("/carousel/carousel")
public class WechatCarouselController extends BaseController
{
    @Autowired
    private IWechatCarouselService wechatCarouselService;

    /**
     * 查询轮播图列表
     */
    @ApiOperation("获取轮播图列表 公开接口 可匿名访问（小程序接口，为用户体验度考虑此接口最多返回10条数据）")
    @Anonymous
    @GetMapping("/getList")
    public TableDataInfo listApp()
    {
        startPage();
        WechatCarousel wechatCarousel=new WechatCarousel();
        wechatCarousel.setCarouselShow(1);
        List<WechatCarousel> list = wechatCarouselService.selectWechatCarouselList(wechatCarousel);
        return getDataTable(list);
    }
    /**
     * 获取轮播图详细信息
     */
    @ApiOperation("根据id获取轮播图 公开接口 可匿名访问（小程序和后台管理系统接口）")
    @Anonymous()
    @GetMapping(value = "/{carouselId}")
    public AjaxResult getInfo(@PathVariable("carouselId") Long carouselId)
    {
        return success(wechatCarouselService.selectWechatCarouselByCarouselId(carouselId));
    }
    /**
     * 查询轮播图列表
     */
    @ApiOperation("获取轮播图列表（后台管理系统接口）")
    @PreAuthorize("@ss.hasPermi('carousel:carousel:list')")
    @GetMapping("/list")
    public TableDataInfo list(WechatCarousel wechatCarousel)
    {
        startPage();
        List<WechatCarousel> list = wechatCarouselService.selectWechatCarouselList(wechatCarousel);
        return getDataTable(list);
    }
    /**
     * 是否展示
     */
    @ApiOperation("轮播图展示状态修改接口（后台管理系统接口）")
    @PreAuthorize("@ss.hasPermi('system:schools:add')")
    @PutMapping("/changeShow")
    public AjaxResult changeShow(@RequestBody ShowVo showVo)
    {
        return AjaxResult.success(wechatCarouselService.changeShow(showVo));
    }

    /**
     * 导出轮播图列表
     */
    @PreAuthorize("@ss.hasPermi('carousel:carousel:export')")
    @Log(title = "轮播图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WechatCarousel wechatCarousel)
    {
        List<WechatCarousel> list = wechatCarouselService.selectWechatCarouselList(wechatCarousel);
        ExcelUtil<WechatCarousel> util = new ExcelUtil<WechatCarousel>(WechatCarousel.class);
        util.exportExcel(response, list, "轮播图数据");
    }



    /**
     * 新增轮播图
     */
    @ApiOperation("新增轮播图（后台管理系统接口）")
    @PreAuthorize("@ss.hasPermi('carousel:carousel:add')")
    @Log(title = "轮播图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WechatCarousel wechatCarousel)
    {
        return toAjax(wechatCarouselService.insertWechatCarousel(wechatCarousel));
    }

    /**
     * 修改轮播图
     */
    @ApiOperation("修改轮播图（后台管理系统接口）")
    @PreAuthorize("@ss.hasPermi('carousel:carousel:edit')")
    @Log(title = "轮播图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WechatCarousel wechatCarousel)
    {
        return toAjax(wechatCarouselService.updateWechatCarousel(wechatCarousel));
    }

    /**
     * 删除轮播图
     */
    @ApiOperation("删除轮播图（后台管理系统接口）")
    @PreAuthorize("@ss.hasPermi('carousel:carousel:remove')")
    @Log(title = "轮播图", businessType = BusinessType.DELETE)
	@DeleteMapping("/{carouselIds}")
    public AjaxResult remove(@PathVariable Long[] carouselIds)
    {
        return toAjax(wechatCarouselService.deleteWechatCarouselByCarouselIds(carouselIds));
    }
}
